package com.wz.project.position.code.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.position.code.domain.PositionCode;
import com.wz.project.position.code.service.IPositionCodeService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 车间站点配置Controller
 * 
 * @author wz
 * @date 2023-12-13
 */
@Controller
@RequestMapping("/system/code")
public class PositionCodeController extends BaseController
{
    private String prefix = "system/code";

    @Autowired
    private IPositionCodeService positionCodeService;

    @RequiresPermissions("system:code:view")
    @GetMapping()
    public String code()
    {
        return prefix + "/code";
    }

    /**
     * 查询车间站点配置列表
     */
//    @RequiresPermissions("system:code:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PositionCode positionCode)
    {
        startPage();
        List<PositionCode> list = positionCodeService.selectPositionCodeList(positionCode);
        return getDataTable(list);
    }

    /**
     * 导出车间站点配置列表
     */
    @RequiresPermissions("system:code:export")
    @Log(title = "车间站点配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PositionCode positionCode)
    {
        List<PositionCode> list = positionCodeService.selectPositionCodeList(positionCode);
        ExcelUtil<PositionCode> util = new ExcelUtil<PositionCode>(PositionCode.class);
        return util.exportExcel(list, "code");
    }

    /**
     * 新增车间站点配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车间站点配置
     */
    @RequiresPermissions("system:code:add")
    @Log(title = "车间站点配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PositionCode positionCode)
    {
        return toAjax(positionCodeService.insertPositionCode(positionCode));
    }

    /**
     * 修改车间站点配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PositionCode positionCode = positionCodeService.selectPositionCodeById(id);
        mmap.put("positionCode", positionCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存车间站点配置
     */
    @RequiresPermissions("system:code:edit")
    @Log(title = "车间站点配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PositionCode positionCode)
    {
        return toAjax(positionCodeService.updatePositionCode(positionCode));
    }

    /**
     * 删除车间站点配置
     */
    @RequiresPermissions("system:code:remove")
    @Log(title = "车间站点配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(positionCodeService.deletePositionCodeByIds(ids));
    }
}
